<template >
  <div>
    <h1>tab切换</h1>
     <ul class="title_list">
      <li :class="index==tabIndex?'active':''"  v-for="(item,index) in tabList" :key="item.title" @click="changeIndex(index)">
        {{item.title}}
      </li>
     </ul>
     <div class="content">
       <div v-show="tabIndex==0">军事内容</div>
       <div v-show="tabIndex==1">科技内容</div>
       <div v-show="tabIndex==2">百家内容</div>
       <div v-show="tabIndex==3">图片内容</div>
     </div>
  </div>
</template>
<script>
export default {
   name:"user",
   data(){
    return {
      tabIndex:0,//默认的激活下标
      tabList:[
          {title:"军事"},
          {title:"科技"},
          {title:"百家"},
          {title:"图片"},
      ]
    }
   },
   methods:{
    changeIndex(index){ //切换激活下标
      this.tabIndex=index;
    }
   }
}
</script>
<style lang="scss">
    .title_list{
      width: 500px;
      list-style:none;
      display: flex;
      li{
        width: 100px;
        height: 60px;
        text-align: center;
        line-height: 60px;
        border: 1px solid #ccc;
        cursor: pointer;
        &.active{
          background: red;
          font-size: 30px;
        }
      }
    }
    .content{
          width: 500px;
          height: 300px;
          div{
              width: 500px;
              height: 300px;
              border: 1px solid #ccc;
           
          }
    }
</style>